// testcmd project main.go
package main

import (
	"fmt"
)

var container = []string{"zero", "one", "two"}

type Integer int

func (a Integer) Less(b Integer) bool {
	return a < b
}
func (a *Integer) Add(b Integer) {
	*a += b
}

func Add(x, y int) {
	z := x + y
	fmt.Println(z)
}

func Count(ch chan int) {
	ch <- 1
	fmt.Println("Counting")
}

func main() {

	chs := make([]chan int, 10)
	for i := 0; i < 10; i++ {
		chs[i] = make(chan int)
		go Count(chs[i])
	}

	for _, ch := range chs {
		<-ch
	}

	//	for i := 0; i < 10; i++ {
	//		go Add(i, i)
	//	}

	var a Integer = 1
	if a.Less(2) {
		fmt.Println(a, "Less 2")
	}

	a.Add(2)
	fmt.Println("a = ", a)

	var I float32 = 0.0
	var bonus float32 = 0.0
	fmt.Print("输入利润：")
	fmt.Scanf("%f\n", &I)
	switch {
	case I > 1000000:
		bonus = (I - 1000000) * 0.01
		I = 1000000
		fallthrough
	case I > 600000:
		bonus += (I - 600000) * 0.015
		I = 600000
		fallthrough
	case I > 400000:
		bonus += (I - 400000) * 0.03
		I = 400000
		fallthrough
	case I > 200000:
		bonus += (I - 200000) * 0.05
		I = 200000
		fallthrough
	case I > 100000:
		bonus += (I - 100000) * 0.075
		I = 100000
		fallthrough
	default:
		bonus += I * 0.1
		fmt.Printf("default：%f\n", bonus)
	}
	fmt.Printf("提成总计：%f\n", bonus)
	for i := 1; i < 5; i++ {
		for j := 1; j < 5; j++ {
			for k := 1; k < 5; k++ {
				if i != k && i != j && j != k {
					fmt.Println(i, j, k)
				}
			}
		}
	}

	s1 := make([]int, 5)
	fmt.Printf("The value of s1 is: %v\n", s1)
	fmt.Printf("The length of s1 is: %d\n", len(s1))
	fmt.Printf("The capacity of s1 is: %d\n", cap(s1))
	fmt.Printf("The value of s1 is: %d\n", s1)

	container := map[int]string{0: "zero", 1: "one", 2: "two"}

	_, ok1 := interface{}(container).([]string)
	_, ok2 := interface{}(container).(map[int]string)
	if !(ok1 || ok2) {
		fmt.Printf("Error: unsupported container type: %T\n", container)
		return
	}
	fmt.Printf("The element is %q.(container type: %T)\n", container[1], container)
	elem, err := getElement(container)
	if err != nil {
		fmt.Printf("Error: %s\n", err)
		return
	}
	fmt.Printf("The element is %q. (container type : %T)\n", elem, container)

}
func getElement(containerI interface{}) (elem string, err error) {
	switch t := containerI.(type) {
	case []string:
		elem = t[1]
	case map[int]string:
		elem = t[1]
	default:
		err = fmt.Errorf("unspported container type : %T", container)
		return
	}
	return
}
